package com.itheima.reggie.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
@Component
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R handlerSQLConstraintException(SQLIntegrityConstraintViolationException exception){
        log.error(exception.getMessage());

        return R.error("账号已存在");
    }

    @ExceptionHandler(BusinessException.class)
    public R handlerBusinessException(BusinessException exception){
        log.error(exception.getMessage());

        return R.error(exception.getMessage());
    }
}
